﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using XCore.Authorization;
using XCore.Domain.Dto;
using XCore.Domain.Dto.Page;
using XCore.Extensions;
using Web.Client.Model;
using SaaS.Cache.Sites;

namespace Web.Client.Controllers
{
    /// <summary>
    /// 运营平台
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OperationController : ClientControllerBase
    {
        private readonly ProjectCacheService _projectCacheService;
        public OperationController(ProjectCacheService projectCacheService)
        {
            _projectCacheService = projectCacheService;
        }
        /// <summary>
        /// 获取运营平台
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult<OperationModel> List()
        {
            var query = SCC.Operations.Where(c => c.UserId == Session.UserId);
            return PageResult(query.OrderByDescending(c => c.CreationTime), c => new
            {
                Name = _projectCacheService.GetName(c.ProjectId),
                Status = c.Status.GetDescription(),
                Type = c.Type.GetDescription(),
                StartTime = c.StartTime.ToString("yyyy-MM-dd"),
                EndTime = c.EndTime.ToString("yyyy-MM-dd"),
                CreationTime = c.CreationTime.ToString("yyyy-MM-dd HH:mm:ss")
            });
        }
    }
}